package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/09/17 11:37
 */
public class MaxSubArrayTest {

    public static void main(String[] args) {

    }

    public static int maxSubArray(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int sum = nums[0];
        int result = nums[0];

        for (int i = 1; i < nums.length; i++) {
            if (sum > 0) {
                sum = sum + nums[i];
            } else {
                sum = nums[i];
            }
            result = Math.max(sum, result);
        }
        return result;
    }
}
